package com.bw.skill.mvvm.viewmodel;

import androidx.databinding.ObservableField;

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.bw.mvvm_common.dao.GoodBean;
import com.bw.mvvm_common.dao.UserBean;
import com.bw.mvvm_common.entity.BaseEntity;
import com.bw.mvvm_common.mvvm.utils.GreenDaoUtils;
import com.bw.mvvm_common.mvvm.viewmodel.BaseViewModel;
import com.bw.skill.entity.AddSeckillEntity;
import com.bw.skill.entity.AddShopEntity;
import com.bw.skill.mvvm.model.SeckillValuesModel;

import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.List;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public
/**
 * @author Lishaohe
 * @description:
 * @date :2021/10/27 0027 上午 9:55
 *
 */
class SeckillValuesViewModel extends BaseViewModel<SeckillValuesModel> {
    public ObservableField<String> title = new ObservableField<>();
    public ObservableField<String> price = new ObservableField<>();
    public ObservableField<String> desc = new ObservableField<>();


    String sku1;
    String desc1;
    String price1;
    String icon1;
    int id1;
    int count1;
    public static long time1;


    @Override
    public void onCreate() {
        super.onCreate();
        title.set(desc1);
        price.set(price1);
        desc.set(sku1);

    }
    public void car(){
        List<UserBean> list = GreenDaoUtils.getGreenDaoUtils().green().queryBuilder().list();
        int userId = list.get(0).getUser_id();

        if (list.isEmpty()){
            ToastUtils.showLong("请登录");
        }else {
            HashMap<String,Object> car = new HashMap<>();
            car.put("goodsCount",count1);
            car.put("goodsDesc",desc1);
            car.put("goodsIcon",icon1);
            car.put("goodsId",id1);
            car.put("goodsPrice",price1);
            car.put("goodsSku",sku1);
            car.put("time",time1);
            car.put("userId",userId);
            m.requestGoodsSeckill(car)
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribeOn(Schedulers.io())
                    .subscribe(this);
        }

    }

    @Override
    protected void result(BaseEntity entity) {
        if (entity instanceof AddSeckillEntity){
            AddSeckillEntity addSeckillEntity = (AddSeckillEntity) entity;
            if (addSeckillEntity.getMessage().equals("添加购物车成功")){
                ToastUtils.showLong("抢购成功");
            }else {
                ToastUtils.showLong("sb");
            }
        }

    }
    public void seckill(String icon, String sku, String desc, String price, int count, int id, long time){
        icon1 =icon;
        sku1 = sku;
        desc1 = desc;
        price1 = price;
        count1 = count;
        id1 = id;


    }


    public void finishActivity(){
        finishPage();
    }
    public void share(){

    }
    public void carList(){

    }
    public void addCar(){

        car();
    }
}
